<?php

include('pagina.php');
include('database.php');
include('auth.php');
include('core.php');

// Valida se esta autenticado
validaPermissao(1);

if ($_GET['submit'] == 'Submit')
{
	// Get employee name
	$employee = query_fetch("SELECT contacts.name, contacts.email from employees,contacts WHERE " .
		"employees.id={$_SESSION[site_id]['id']} AND employees.contact_id=contacts.id LIMIT 1");

	$message = top_msg . "\n" .
	"Error Report\n\n" .
	$employee['name'] . " requested a report error with the folowing information:\n" .
	"Location: " . $_GET['location'] . "\n" .
	"Date: " . $_GET['date'] . "\n" .
	"In: " . $_GET['in_time'] . ", Out: " . $_GET['out_time'] . "\n" .
	($_GET['obs']? "Observations:\n" . $_GET['obs'] : "");

	$headers = "From: Parksys <" . admin_email . ">\r\n" .
	"Reply-To: " . $employee['name'] . " <" . ($employee['email']? $employee['email'] : admin_email) . ">\r\n" .
	"X-Mailer: Parksys";

	// Send email
	if (mail("Office Manager <" . office_email . ">", "Error report", $message, $headers))
		header("Location: report_error.php?msg=Thank you. Your error report was submited for revision.");
	else
		header("Location: report_error.php?msg=Could not send e-mail. Please contact admin.");
	die();
}
else
{
	$_GET['msg'] = 'Please enter the correct information for the wrong or missing report.';
}

// Inicia cabecalho da pagina
pagina_inicio('Report error');
adicionar_css('datechooser.css');
adicionar_js('datechooser.js');
adicionar_js('input-format.js');
pagina_head();

?>
<script type="text/javascript" language="JavaScript">
function checkForm()
{

	if (document.getElementById('date').value.length == 0)
	{
		alert("Please specify a date.");
		return false;
	}
	if (document.getElementById('location').value.length == 0)
	{
		alert("Please specify a location.");
		return false;
	}
	if (document.getElementById('in_time').value.length == 0)
	{
		alert("Please specify a in time in the format HH:MM.");
		return false;
	}
	if (document.getElementById('out_time').value.length == 0)
	{
		alert("Please specify a out time in the format HH:MM.");
		return false;
	}
	else
		return true;
}
</script>

<br><form id=reporterror method=GET class=big_form action=report_error.php onSubmit="return checkForm()">
<h1>Error Report</h1><br>
<label for=date>Date:</label> <input id=date type=TEXT name='date' size=9>
	<img class=imgcalendar src='img/calendar.gif' onclick="showChooser(this, 'date', 'chooserSpan1', 2000, 2020, Date.patterns.ShortDatePattern, false); " alt='calendar'>
	<div id='chooserSpan1' class='dateChooser select-free' style='display: none; visibility: hidden; width: 160px;'></div><br>
<label for=location>Location:</label> <input type=TEXT name=location id=location><br>
<label for=in_time>In:</label> <input type=TEXT id=in_time name='in_time'
	title='Enter time on HHMM hour format' onChange='format_int(this)' size=5 maxlength=4>
<label for=out_time>Out:</label> <input type=TEXT id=out_time name='out_time'
	title='Enter time on HHMM hour format' onChange='format_int(this)' size=5 maxlength=4><br>

<label for=obs>Observations:</label><br><textarea id=obs name=obs cols=40 rows=5>
</textarea><br>

<input type=SUBMIT name=submit value='Submit'>
</form>

<?php
// Finaliza pagina
pagina_fim();
?>
